﻿using System.Collections.Generic;
using System.Linq;
using Caliburn.Micro;
using CardPlay.Model;

namespace CardPlay.Client.Model
{
    public static class GameRepository
    {
        private static IGameDescriptor[] _gamesCache;

        public static IEnumerable<IGameDescriptor> Games
        {
            get
            {
                return _gamesCache ?? (_gamesCache = IoC.GetAllInstances(typeof(IGamePackage))
                        .Cast<IGamePackage>()
                        .SelectMany(pack => pack.Games)
                        .OrderBy(game => game.DisplayName)
                        .ToArray());
            }
        }

        public static IStorage History
        {
            get { return IoC.Get<IStorage>(); }
        }
    }
}